package com.ruicar.afs.cloud.apply.admin.manage.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.admin.entity.SysPermission;
import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import com.ruicar.afs.cloud.common.core.entity.BaseEntity;
import com.ruicar.afs.cloud.common.core.security.vo.UserVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * The type SysUser.
 * <p>
 * Created on 2019-02-20
 *
 * @author Fzero
 */
@Data
@TableName("sys_user")
public class SysUser implements Serializable  {

    /**
     * The constant serialVersionUID.
     */
    private static final long serialVersionUID = 1L;

    /**
     * The User id.
     */
    @TableId(value = "user_id")
    @JsonSerialize(using = ToStringSerializer.class)
    @JSONField(serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class)
    private Long userId;
    /**
     * The Username.
     */
    private String username;

    /**
     * The User real name.
     */
    private String userRealName;
    /**
     * The Password.
     */
    private String password;
    /**
     * The Create time.
     */
    private Date createTime;
    /**
     * The Update time.
     */
    private Date updateTime;
    /**
     * The Del flag.
     */
    @TableLogic
    private String delFlag = CommonConstants.STATUS_NORMAL;;

    /**
     * The Lock flag.
     */
    private String lockFlag;

    /**
     * The Phone.
     */
    private String phone;
    /**
     * The User email.
     */
    private String userEmail;

    /**
     * The Dept id.
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deptId;

    private String tenantId;

    /**
     * 身份证号
     */
    private String identityNumber;
    /**
     * 渠道ID码
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long channelId;

    @JsonSerialize(using = ToStringSerializer.class)
    @JSONField(serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class)
    /** 密码最后修改时间 */
    private Long lastPassChangeTime;
    /**
     * 密码错误次数
     */
    private Integer passErrorCount;
    /**
     * 最后登录失败时间
     */
    private Long lastLoginFailTime;
    @TableField(exist = false)
    @ApiModelProperty(value = "所属部门名称")
    private String departmentTitle;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有二手车角色")
    private List<SysRole> oldRoles;
    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有新车角色")
    private List<SysRole> newRoles;


    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的权限")
    private List<SysPermission> permissions;

    public UserVo transToUserVo() {
        UserVo rtnvo = new UserVo();
        BeanUtils.copyProperties(this, rtnvo);
        return rtnvo;
    }

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的角色")
    private String roleName;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的角色")
    private String newApplyPower;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的角色")
    private String odlApplyPower;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的角色")
    private String newAccountPower;

    @TableField(exist = false)
    @ApiModelProperty(value = "用户拥有的角色")
    private String oldAccountPower;

    @TableField(exist = false)
    @ApiModelProperty(value = "是否管理员")
    private String userManage;

}
